package net.sudot.chess.business.wechat.message;

import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import net.sudot.chess.business.model.Customer;
import net.sudot.chess.business.model.Room;
import net.sudot.chess.business.model.User;
import net.sudot.chess.config.SystemProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 赛程安排通知
 * <pre>
 * {{first.DATA}}
 * 比赛名称：{{keyword1.DATA}}
 * 比赛开始时间：{{keyword2.DATA}}
 * 比赛房间号：{{keyword3.DATA}}
 * 房间密码：{{keyword4.DATA}}
 * {{remark.DATA}}
 * <p/>
 * 最终发送示例:
 * <p/>
 * xxx，您报名的牌局已组建成功：
 *
 * 比赛名称：XXX
 * 比赛开始时间：2018-04-03 07:57
 * 比赛房间号：123456
 * 房间密码：无需密码
 *
 * 点击进入聊天室，确认人员后进入游戏，祝您取得胜利
 * </pre>
 *
 * @author tangjialin on 2018-04-01.
 */
@Component
public class PlayTemplateMessage extends AbstractTemplateMessage {

    @Value("${system.config.wechat.playTempleteId}")
    private String templateId;

    @Override
    public String getTemplateId() {
        return templateId;
    }

    @Override
    protected WxMpTemplateMessage.WxMpTemplateMessageBuilder builderTemplateMessage(User user, Object data, SystemProperties systemProperties) {
        Customer customer = (Customer) user;
        Room room = (Room) data;
        List<WxMpTemplateData> templateData = new ArrayList<>();
        templateData.add(new WxMpTemplateData("first", customer.getNickname() + "，您报名的牌局已组建成功\n"));
        templateData.add(new WxMpTemplateData("keyword1", String.format("[第%s期]%s【%s】", room.getPeriod(), room.getName(), room.getRegion())));
        templateData.add(new WxMpTemplateData("keyword2", "即刻开始"));
        templateData.add(new WxMpTemplateData("keyword3", room.getSn()));
        templateData.add(new WxMpTemplateData("keyword4", "无需密码"));
        templateData.add(new WxMpTemplateData("remark", "\n点击进入聊天室，或进入APP输入房间号[" + room.getSn() + "]，祝您取得胜利"));
        WxMpTemplateMessage.WxMpTemplateMessageBuilder builder = WxMpTemplateMessage.builder().data(templateData);
        builder.url(systemProperties.getWebsite() + "/room/chat");
        return builder;
    }

}
